<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/28
 * Time: 10:22
 */

/*
您在淘宝开放平台成功创建liu526130应用，您的Appkey 和 Appsecret如下：
App Key： 23870173
App Secret： 7a216b47de34fbd713879f01aa967706
接下来您将使用您的APPkey和APPsecret进行应用开发和发布。如果您是第一次开发，建议您详细阅读我们的开发文档，您还可以通过阅读我们的接入指南了解开发流程。

同时TOP也将不断的完善和推出新的服务，这些信息将会通过论坛公告的形式推送给广大开发者，敬请关注*/

$appkey = "23870173";
$appSecret = "7a216b47de34fbd713879f01aa967706";
$redirect_url = "";
$url = "https://oauth.taobao.com/authorize?response_type=code&client_id=#appKey#&redirect_uri=http://www.oauth.net/2/&state=1212&view=web";

//$appKey = "23870511";

 $url = 'https://oauth.taobao.com/token';
 $postfields= array('grant_type'=>'authorization_code',
     'client_id'=>$appkey,
     'client_secret'=>$appSecret,
     'code'=>'WF39IOvHQFHxCpg6e0VKBF1Y331746',
     'redirect_uri'=>'http://tb.yangjifang.com');
 $post_data = '';

 foreach($postfields as $key=>$value){
     $post_data .="$key=".urlencode($value)."&";}
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
 curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);

 //指定post数据
 curl_setopt($ch, CURLOPT_POST, true);

 //添加变量
 curl_setopt($ch, CURLOPT_POSTFIELDS, substr($post_data,0,-1));
 $output = curl_exec($ch);
 $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
 echo $httpStatusCode;
 curl_close($ch);
 var_export($output);

//https://oauth.taobao.com/authorize?response_type=code&client_id=23870173&redirect_uri=http://tb.yangjifang.com&state=1212&view=web
//用后台的返回地址后台的appkey


200'{"taobao_user_nick":"%E8%8A%B1%E8%8A%B1%E7%9A%84%E4%B8%96%E7%95%8Cliu","re_expires_in":3600,"expires_in":86400,"expire_time":1496055482047,"r1_expires_in":86400,"w2_valid":1495970882047,"w2_expires_in":1800,"taobao_user_id":"2804941164","w1_expires_in":86400,"r1_valid":1496055482047,"r2_valid":1496055482047,"w1_valid":1496055482047,"r2_expires_in":86400,"token_type":"Bearer","refresh_token":"6200126b35eae2333906550631fa625bf5ZZfc2606439b42804941164","refresh_token_valid_time":1495972682047,"access_token":"6202926158f145133484e463c194d22572ZZ843d8fb7cf42804941164"}'
?>